<template>
	<view class="gsxx">
		<u-navbar bgColor="#fff">
			<view slot="left" class="align-center">
				<image @click="$tools.back()" src="@/static/login/back3.png" style="width: 36rpx; height: 36rpx"></image>
			</view>
			<view slot="center">
				<view style="font-weight: 600; font-size: 36rpx; color: #333333">公司信息</view>
			</view>
		</u-navbar>
		<view style="padding: 32rpx">
			<view style="border-bottom: 1rpx solid #eeeeee; margin-bottom: 30rpx">
				<view style="font-weight: 300; font-size: 24rpx; color: #333333">公司名称</view>
				<view class="flex-between1" style="margin-bottom: 14rpx; padding: 10rpx 0 30rpx 0">
					<input v-model="form.name" :disabled="true" style="font-size: 28rpx; color: #333333" />
				</view>
			</view>
			<view style="border-bottom: 1rpx solid #eeeeee; margin-bottom: 30rpx">
				<view style="font-weight: 300; font-size: 24rpx; color: #333333">*所在位置</view>
				<view class="flex-between1" style="margin-bottom: 14rpx; padding: 10rpx 0 30rpx 0">
					<input v-model="form.address" :disabled="true" style="font-size: 28rpx; color: #333333" />
				</view>
			</view>
			<view style="border-bottom: 1rpx solid #eeeeee; margin-bottom: 30rpx">
				<view style="font-weight: 300; font-size: 24rpx; color: #333333">联系电话</view>
				<view class="flex-between1" style="margin-bottom: 14rpx; padding: 10rpx 0 30rpx 0">
					<input v-model="form.phone" :disabled="true" type="number" placeholder="请输入" style="font-size: 28rpx; color: #333333" />
				</view>
			</view>
			<view style="border-bottom: 1rpx solid #eeeeee; margin-bottom: 30rpx">
				<view style="font-weight: 300; font-size: 24rpx; color: #333333">公司资质</view>
				<!-- <view style="font-weight: 400; font-size: 28rpx; color: #999999">上传公司营业执照等</view> -->
				<view class="flex-between" style="margin-bottom: 14rpx; padding: 10rpx 0 30rpx 0">
					<u-upload
						:deletable="false"
						:fileList="fileList1"
						@afterRead="afterRead"
						@delete="deletePic"
						name="1"
						multiple
						:maxCount="0"
						width="100"
						height="100"
						uploadIcon="plus"
					></u-upload>
					<!-- <image src="@/static/mine/mineright.png" style="width: 16rpx; height: 26rpx"></image> -->
				</view>
			</view>
		</view>
		<view class="flex-center1">
			<!-- <view
				@click="updateCompany"
				class="flex-center1"
				style="font-weight: 600; font-size: 32rpx; color: #ffffff; width: 640rpx; height: 96rpx; background: #1365f9; border-radius: 16rpx"
			>
				提交
			</view> -->
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			fileList1: [],
			form: {
				name: '',
				address: '',
				phone: '',
				businessLicense: ''
			}
		};
	},
	onShow() {
		this.init();
	},
	methods: {
		init() {
			this.$request('front/company/companyDetail').then((res) => {
				console.log(res, 'sss');
				this.form = res.obj;
				if (this.form.businessLicense) {
					const imglist = this.form.businessLicense.split(',');
					imglist.map((item, index) => {
						this.$set(this.fileList1, index, { url: item });
					});
				}
			});
		},
		updateCompany() {
			const data = this.form;
			this.$request('front/company/updateCompany', data).then((res) => {
				console.log(res, 'sss');
				this.$tools.toast('操作成功');
				setTimeout(() => {
					this.$tools.back();
				}, 1000);
			});
		},

		setimg(event, key) {
			const list = [];
			this[`fileList${event.name}`].map((item, index) => {
				list.push(item.url);
			});
			const fileList1str = list.join(',');
			this.form.businessLicense = fileList1str;
			console.log(this.form.businessLicense, 'image');
		},
		// 删除图片
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1);
			this.setimg(event);
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file);
			let fileListLen = this[`fileList${event.name}`].length;
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				});
			});
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url);
				let item = this[`fileList${event.name}`][fileListLen];
				this[`fileList${event.name}`].splice(
					fileListLen,
					1,
					Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					})
				);
				fileListLen++;
			}

			this.setimg(event);
		}
	}
};
</script>

<style lang="less" scoped>
.gsxx {
	padding: 200rpx 0 0;
}
</style>
